package com.greendragon.persistence.dao.impl; 

import java.util.List;

import org.apache.log4j.Logger;

import com.greendragon.persistence.dao.ICategoryDao;
import com.greendragon.persistence.domain.ArticalCategory;
import com.greendragon.persistence.enmu.FetchOrderType;

/** 
 * @author wulibin, exceptsky@gmail.com, 2011-9-30 下午05:36:05
 * 
 */
public class ArticalCategoryDaoImpl extends BaseDao<ArticalCategory> implements ICategoryDao<ArticalCategory>{
	private static Logger          logger           = Logger.getLogger(ArticalCategoryDaoImpl.class);
	
	@Override
	@SuppressWarnings("unchecked")
	public ArticalCategory getByName(String name) {
		String hql = "from ArticalCategory ac where ac.name = ?";
		
		try {
			List rs = getHibernateTemplate().find(hql, name);
			if(rs==null || rs.size()==0){
				return null;
			}
			ArticalCategory result = (ArticalCategory)rs.listIterator().next();
			return result;
		} catch (Exception e) {
			logger.error(e);
			return null;
		}
		
	}

	@Override
	public List<ArticalCategory> getAllRootCategories(int offset, int length, FetchOrderType orderType) {
		String hql = "from ArticalCategory as ac where ac.parentCategory is null"+getOrderSql("ac",orderType);
		return selectByPage(hql, null, offset, length);
	}
}
 